package ru.psu.holycow.library.agent;

import java.io.IOException;

import ru.psu.holycow.library.event.IEvent;
import ru.tomtrix.trixmq.IEndPointListener;
import ru.tomtrix.trixmq.ListenerCommands;
import ru.tomtrix.trixmq.MQClient;
import ru.tomtrix.trixmq.MQServer;

public class SynchManager
{
	private final MQServer _server;
	private final MQClient _client;
	
	public SynchManager(final EventList evlist) throws IOException
	{
		_server = new MQServer(4646, new IEndPointListener()
		{
			@Override
			public void notifyMe(ListenerCommands cmd, Object data)
			{
				if (cmd == ListenerCommands.NewMessage)
					evlist.add((IEvent) data);
			}
		});
		_client = new MQClient(new IEndPointListener()
		{
			@Override
			public void notifyMe(ListenerCommands cmd, Object data)
			{
				if (cmd == ListenerCommands.NewMessage)
					evlist.add((IEvent) data);
			}
		});
	}
}
